home *** CD-ROM | disk | FTP | other *** search
/ Aminet 28 / Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso / Aminet / dev / misc / gms_dev.lha / GMSDev / Source / C / Misc / ConfigLoader.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-09  |  2.1 KB  |  81 lines

  1. /*
  2. ** This demo will load the TEST.CNF config file and then print out
  3. ** some of the details in it.  This illustrates how you can use config
  4. ** files for user modifications etc.
  5. **
  6. */
  7.  
  8. #include <proto/dpkernel.h>
  9. #include <files/files.h>
  10. #include <misc/config.h>
  11. #include <pragmas/config_pragmas.h>
  12.  
  13. BYTE *ProgName      = "Config Loader";
  14. BYTE *ProgAuthor    = "Paul Manias";
  15. BYTE *ProgDate      = "August 1998";
  16. BYTE *ProgCopyright = "DreamWorld Productions (c) 1998.";
  17. BYTE *ProgShort     = "Tests the configuration module.";
  18.  
  19. struct Module *ConfigMod;
  20. APTR CNFBase;
  21.  
  22. struct FileName FName = {
  23.   ID_FILENAME, "TEST.CNF"
  24. };
  25.  
  26. void main()
  27. {
  28.    LONG result, i;
  29.    BYTE *buffer;
  30.    struct Config *Config;
  31.  
  32.    if (ConfigMod = OpenModule(MOD_CONFIG,"config.mod")) {
  33.       CNFBase = ConfigMod->ModBase;
  34.  
  35.       if (Config = InitTags(NULL,
  36.          TAGS_CONFIG, NULL,
  37.          CFA_Source, &FName,
  38.          TAGEND)) {
  39.  
  40.          /* Use this loop if you want to search an entire
  41.          ** configuration object.
  42.          */
  43.  
  44.          for(i=NULL; i < Config->AmtEntries; i++) {
  45.             if (Config->Entries[i].Item) {
  46.                DPrintF("!Demo:","Section: %s, Item: %s, Data: \"%s\"",Config->Entries[i].Section,Config->Entries[i].Item,Config->Entries[i].Data);
  47.             }
  48.             else {
  49.                DPrintF("!Demo:","Array: %s",Config->Entries[i].Section);
  50.             }
  51.          }
  52.  
  53.          /* This function picks up specific fields */
  54.  
  55.          if (buffer = ReadConfig(Config,"Map","Terrain")) {
  56.             DPrintF("!MAP:Terrain:","%s",buffer);
  57.          }
  58.  
  59.          if (buffer = ReadConfig(Config,"Map","Width")) {
  60.             DPrintF("!MAP:Width:","%s",buffer);
  61.          }
  62.  
  63.          /* Read an integer */
  64.  
  65.          result = ReadConfigInt(Config,"Map","Height");
  66.          DPrintF("!MAP:Height:","%d",result);
  67.  
  68.          /* Use this method if you want to read an array */
  69.  
  70.          if ((buffer = ReadConfig(Config,"Waypoints",NULL))) {
  71.             /*DPrintF("!MAP:Waypoints:","%s",buffer);*/
  72.          }
  73.          else DPrintF("!Demo:","Failed to read array from config file.");
  74.  
  75.       Free(Config);
  76.       }
  77.    Free(ConfigMod);
  78.    }
  79. }
  80.  
  81.